package com.caoustc.okhttplib.utils

object ObjectUtils {
    fun isEquals(actual: Any?, expected: Any?): Boolean {
        return actual === expected || if (actual == null) expected == null else actual == expected
    }

    fun transformLongArray(source: LongArray): Array<Long?> {
        val destin = arrayOfNulls<Long>(source.size)
        for (i in source.indices) {
            destin[i] = source[i]
        }
        return destin
    }

    fun transformLongArray(source: Array<Long>): LongArray {
        val destin = LongArray(source.size)
        for (i in source.indices) {
            destin[i] = source[i]
        }
        return destin
    }

    fun transformIntArray(source: IntArray): Array<Int?> {
        val destin = arrayOfNulls<Int>(source.size)
        for (i in source.indices) {
            destin[i] = source[i]
        }
        return destin
    }

    fun transformIntArray(source: Array<Int>): IntArray {
        val destin = IntArray(source.size)
        for (i in source.indices) {
            destin[i] = source[i]
        }
        return destin
    }

    fun <V> compare(v1: V?, v2: V?): Int {
        return if (v1 == null) {if (v2 == null) 0 else -1 } else if (v2 == null) 1 else (v1 as Comparable<Any>).compareTo(v2)
    }
}